package com.datasentinel.rooms.j3d.util;

import javax.media.j3d.Appearance;
import javax.media.j3d.Geometry;
import javax.media.j3d.Material;
import javax.media.j3d.QuadArray;
import javax.media.j3d.Shape3D;

public class PlaneShape3D extends Shape3D
{
	protected static final float[][] vertexCoords = { { -1, 1, 0 }, { -1, -1, 0 }, { 1, -1, 0 },
			{ 1, 1, 0 } };
	protected static final float[][] texCoords = { { 0, 1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } };
	protected static final float[] normalComponents = { 0, 0, 1 };

	public PlaneShape3D()
	{
		super();
		setGeometry(createGeometry(vertexCoords, texCoords, normalComponents));
		setAppearance(createAppearance());
	}

	protected Geometry createGeometry(float[][] vertexCoords, float[][] texCoords,
			float[] normalCoords)
	{
		QuadArray geometry = new QuadArray(4, QuadArray.COORDINATES | QuadArray.NORMALS
				| QuadArray.TEXTURE_COORDINATE_2);
		for (int i = 0; i < 4; i++)
		{
			geometry.setCoordinate(i, vertexCoords[i]);
			geometry.setNormals(i, normalCoords);
			geometry.setTextureCoordinates(0, i, texCoords[i]);
		}
		return geometry;
	}

	protected Appearance createAppearance()
	{
		Appearance appearance = new Appearance();
		appearance.setCapability(Appearance.ALLOW_TRANSPARENCY_ATTRIBUTES_WRITE);
		appearance.setCapability(Appearance.ALLOW_TEXTURE_WRITE);
		Material material = new Material();
		appearance.setMaterial(material);
		return appearance;
	}
}
